#!/bin/bash
# - test
# - case

. $LKP_SRC/lib/upload.sh


prepare_test()
{
       dnf install -y git
       git clone https://gitee.com/openeuler/mugen.git  $BENCHMARK_ROOT/test-mugen/mugen
       cd $BENCHMARK_ROOT/test-mugen/mugen || exit
}


dns_resolver()
{
	cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 223.5.5.5
EOF
}

set_env()
{       
	export LANG="en_US.UTF-8"
        direct_client_ips=$(ip addr show|grep inet|grep -v inet6|grep -Ewv "lo.*|docker.*|vlan.*|bond.*|virbr.*|br-.*" |awk '{print $2}'|awk -F "/" '{print $1}' |head -1)
	bash dep_install.sh 
	bash mugen.sh -c --ip  $direct_client_ips --password $secrets_userpassword  --user $secrets_username --port 22 
}


test_one_case()
{
	bash mugen.sh -x -f "$test" -r "$case" -x
}

test_one_test()
{
	bash mugen.sh -f "$test" -x
}

test_all_cases()
{
	bash mugen.sh -a
}

upload_results_logs()
{       
	ls results/"$test"/failed >> results/failed_list
	ls results/"$test"/succeed >> results/succeed_list
	upload_files -t logs logs/*
	upload_files -t results results/failed_list
	upload_files -t results results/succeed_list
}

run()
{
	dns_resolver
	prepare_test
	#dns_resolver
	set_env
	if [ -n "$test" ];then
		if [ -n "$case" ];then
			test_one_case
		else
			test_one_test
		fi
	else
		test_all_cases
	fi
	upload_results_logs
}

run
